package com.sync.syncmasterdata;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sync.syncmasterdata.configuration.ConfInfo;
import com.sync.syncmasterdata.customer.service.http.HttpAPIServiceForCrmSync;
import com.sync.syncmasterdata.product.controller.ProductController;
import com.sync.syncmasterdata.product.entity.oa.ProductWorkflowReStoreEntity;
import com.sync.syncmasterdata.product.pojo.cp.InventoryForCP;
import com.sync.syncmasterdata.product.pojo.erp.InventoryForU8;
import com.sync.syncmasterdata.product.pojo.oa.InventoryForOA;
import com.sync.syncmasterdata.product.service.SyncInventoryService;
import com.sync.syncmasterdata.product.service.convert.ProductOAToU8;
import com.sync.syncmasterdata.util.AuthUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;


@SpringBootTest
@Slf4j
class SyncMasterDataApplicationTestsU8open {

//    @Autowired
//    private StringRedisTemplate stringRedisTemplate;


    @Autowired
    private SyncInventoryService syncInventoryService;


    @Autowired
    private ProductOAToU8 productOAToU8;

    @Autowired
    private ConfInfo confInfo;

    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private AuthUtil authUtil;

    @Autowired
    private ProductController productController;

    @Autowired
    private HttpAPIServiceForCrmSync httpAPIService;
    private final String CUS_APP_KEY = "opa77b093bcbce40729";
    private final String CUS_APP_SECRET = "08ac4444d99348598892c3882eb73d48";

    private static final String openapi_url = "http://open.aichezaixian.com/route/rest";
    private static final String PWD_MD5 = "ad92a2ea55e476e52a3632f192b757fd";

    private static final String app_key = "8FB345B8693CCD00955C4CDC3730ADC5";
    private static final String app_secret = "1730daabee994231a5fb743132bda58c";


    @Test
    void contextLoads() {
    }

    /**
     * CP get token 测试
     */
    @Test
    public void testGetu8Token() {
        System.out.println("获取token：" + authUtil.getCPTokenByTag("u8vensync"));
    }

    @Test
    public void redisTest() {
//        stringRedisTemplate.opsForValue().set("key1","key1",500, TimeUnit.SECONDS);
//        System.out.println("获取的缓存数据为："+stringRedisTemplate.opsForValue().get("key1"));
//        System.out.println("获取的缓存数据为："+stringRedisTemplatee.opsForValue().get("kent1"));

    }
    @Test
    public void test(){
        System.out.println("test");
    }

    /**
     * 更新erp 产品接口测试
     */
    @Test
    public void udpateInventoryForTest() {
        InventoryForOA oa = new InventoryForOA();
        oa.setCunhuobm("FW06002");
        oa.setChanpinmc("测试更新forupdate2222");
        oa.setHuohao("for数据库");
        oa.setKuwei("冷冻库");
        oa.setZhujildw("043");
        oa.setPinpaiwb("品牌文本");
        oa.setShengchanqy("N1101002");
        oa.setShengchanqywb("n1101002企业");
        oa.setShifoucgbh(1);
        oa.setShifouylqx(0);
        InventoryForU8 u8 = productOAToU8.convertToForUpdate(oa);
        String ret=syncInventoryService.editInvToOpenU8(u8, "2");
        System.out.println(ret);

    }

    /**
     * 停用erp  产品接口测试
     */
    @Test
    public void delInventoryForTest(){
        String code = "FW01062";
        String ret = syncInventoryService.delInvToOpenU8(code, "2");
        System.out.println("ret------>>"+ret);

    }



    /**
     * 停用erp  产品接口测试
     */
    @Test
    public void delInventoryForTest2(){
        String code = "CL01001";
        ProductWorkflowReStoreEntity entity = new ProductWorkflowReStoreEntity();
        entity.setInventory_code("CL01001");
        entity.setNext_downtime("2025-03-12");
        String ret = syncInventoryService.reStoreInvToOpenU8(entity, "2");
        System.out.println("ret------>>"+ret);

    }

    @Test
    public void beanForTest() {
        InventoryForCP cp = new InventoryForCP();
        cp.setJiliangdwwb("123");
        cp.setShifoucgbh(true);
        try {
            System.out.println(objectMapper.writeValueAsString(cp));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void getInvForTest(){
        syncInventoryService.getInvFromOpenU8("YJ00002");

//        Map<String, Object> map = new HashMap<>();
//        map.put("requestid", "413854");
//        map.put("prod", "0");
//        productController.productPushToTestAPI(map);

    }

    @Test
    public void test2(){
        Map<String, Object> res = new HashMap<>();
        res.put("requestid", "464816");
        res.put("prod", "0");
        productController.productSourceOaByRequestid(res);
    }


}
